const util = require('../../utils/util.js');
var app = getApp();
Page({

  data: {

  },

  onLoad: function (options) {
    console.log(options);
    this.setData({
      length: options.length,
      rightNum: options.rightNum,
      uuid: options.uuid
    })
    this.onGetOpenid();
  },

  onReady: function () {

  },

  onShow: function () {
    
  },
  goHome: function(){
    wx.redirectTo({
      url: "../home/home"
    });
  },
  examBack: function () {
    wx.redirectTo({
      url: "../notes/notes?uuid="+this.data.uuid
    });
  },
  getordernum: function(){
    return util.formatTime(new Date());
  },
  generate: function(){
    return util.formatTime2(new Date());
  },
  
  
  
  
  
  goNewExam: async function(){
    wx.navigateTo({
      url: '/pages/exam/exam',
    })
  },
  exam_repeat: function () {
    this._repeat_examGo(this);
  },

  _repeat_examGo: function (e) {
    if (!e.data.category.time) return wx.showLoading({
      title: "考题读取中"
    }), void setTimeout(function () {
      wx.hideLoading();
    }, 999);
    wx.removeStorage({
      key: "exam" + this.data.category.id
    }), wx.removeStorage({
      key: "examlist" + this.data.category.id
    }), wx.removeStorage({
      key: "examind" + this.data.category.id
    }), wx.removeStorage({
      key: "examids" + this.data.category.id
    }), wx.removeStorage({
      key: "examall" + this.data.category.id
    }), wx.redirectTo({
      url: "../exam/exam?passf=" + e.data.category.passf + "&time=" + (e.data.category.time - 1) + "&training_qids=0&nums=" + e.data.category.number
    });
  },
  onGetOpenid: function() {
    let that = this;
    // 调用云函数
    wx.cloud.callFunction({
      name: 'login',
      data: {},
      success: res => {
        console.log('[云函数] [login]: ', res)
        let openid = res.result.openid;
        app.globalData.openid = openid;
        // that.getRecult(openid);
        that.setData({
          openid: openid
        })
      },
      fail: err => {
        console.error('[云函数] [login] 调用失败', err)
        wx.navigateTo({
          url: '../deployFunctions/deployFunctions',
        })
      }
    })
  }
})